package com.heu.blood.storge.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.heu.blood.common.aop.ControllerLogAnnotation;
import com.heu.blood.storge.vo.BloodWarningVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.heu.blood.storge.entity.BloodStorgeWarningEntity;
import com.heu.blood.storge.service.BloodStorgeWarningService;
import com.heu.blood.common.utils.PageUtils;
import com.heu.blood.common.utils.R;



/**
 * 
 *
 * @author wjh
 * @email 1208325290@heu.com
 * @date 2023-07-25 11:58:46
 */
@Slf4j
@RestController
@RequestMapping("storge/bloodstorgewarning")
public class BloodStorgeWarningController {
    @Autowired
    private BloodStorgeWarningService bloodStorgeWarningService;

    /**
     * 列表
     */
    @ControllerLogAnnotation(module = "血液预警", operate = "分页查询血液预警信息")
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){

        log.info("params : {}", params); // 打印参数
        PageUtils page = bloodStorgeWarningService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @ControllerLogAnnotation(module = "血液预警", operate = "根据id查询血液预警信息")
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		BloodStorgeWarningEntity bloodStorgeWarning = bloodStorgeWarningService.getById(id);

        return R.ok().put("data", bloodStorgeWarning);
    }

    /**
     * 保存
     */
    @ControllerLogAnnotation(module = "血液预警", operate = "插入血液预警信息")
    @RequestMapping("/save")
    public R save(@RequestBody BloodStorgeWarningEntity bloodStorgeWarning){
		bloodStorgeWarningService.save(bloodStorgeWarning);

        return R.ok();
    }

    /**
     * 修改
     */
    @ControllerLogAnnotation(module = "血液预警", operate = "更新血液预警信息")
    @RequestMapping("/update")
    public R update(@RequestBody BloodStorgeWarningEntity bloodStorgeWarning){
		bloodStorgeWarningService.updateById(bloodStorgeWarning);

        return R.ok();
    }

    /**
     * 删除
     */
    @ControllerLogAnnotation(module = "血液预警", operate = "根绝id删除血液预警信息")
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		bloodStorgeWarningService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    @ControllerLogAnnotation(module = "血液预警", operate = "根据血袋阈值进行血液预警")
    @RequestMapping("/storgeWarning")
    public R storgeWarning(@RequestParam Map<String, Object> params){
        PageUtils page = bloodStorgeWarningService.storgeWarningByBagValue(params);

        return R.ok().put("page", page);
    }
    @ControllerLogAnnotation(module = "血液预警", operate = "废弃的根据血液过期时间阈值进行血液预警")
    @RequestMapping("/storgeWarningByTime")
    public R storgeWarningByTime(@RequestParam Map<String, Object> params){
        PageUtils page = bloodStorgeWarningService.storgeWarningByTime(params);
        return R.ok().put("page", page);
    }

    @ControllerLogAnnotation(module = "血液预警", operate = "根据血液过期时间阈值进行血液预警")
    @RequestMapping("/newStorgeWarningByTime")
    public R newStorgeWarningByTime(@RequestParam Map<String, Object> params){
        PageUtils page = bloodStorgeWarningService.newStorgeWarningByTime(params);
        return R.ok().put("page" , page);
    }

    @ControllerLogAnnotation(module = "血液预警", operate = "预警已过期的血液")
    @GetMapping("/expired")
    public R expired(){
        List<BloodWarningVo> result = bloodStorgeWarningService.expired();
        return R.ok().put("data", result);
    }
}
